home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Graphics / Gallery / Source / MainWindow.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-20  |  10.2 KB  |  429 lines

  1. #include <stream.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <ctype.h>
  6.  
  7. #include <clib/utility_protos.h>
  8.  
  9. #include "GUIC_Application.hpp"
  10. #include "GUIC_Checkbox.hpp"
  11. #include "GUIC_Cycle.hpp"
  12. #include "GUIC_Error.hpp"
  13. #include "GUIC_Event.hpp"
  14. #include "GUIC_Exceptions.hpp"
  15. #include "GUIC_File.hpp"
  16. #include "GUIC_FileString.hpp"
  17. #include "GUIC_ImageButton.hpp"
  18. #include "GUIC_Message.hpp"
  19. #include "GUIC_Panel.hpp"
  20. #include "GUIC_PathString.hpp"
  21. #include "GUIC_Screen.hpp"
  22. #include "GUIC_SlidingInteger.hpp"
  23. #include "GUIC_String.hpp"
  24. #include "GUIC_System.hpp"
  25.  
  26. #include "MainWindow.hpp"
  27.  
  28. /*********************************************************************************************************/
  29.  
  30. MainWindowC::MainWindowC             (GUIC_ApplicationC &a, GUIC_ScreenC &s, PrefsWindowC &p, HTMLWindowC &h, ManagerWindowC &m, CompareWindowC &c) : GUIC_WindowC(5,2)
  31. {
  32.     app                 = &a;
  33.     screen             = &s;
  34.     pWindow            = &p;
  35.     hWindow            = &h;
  36.     mWindow        = &m;
  37.     cWindow            = &c;
  38.     
  39.     fileRequester.setPathPart("projects");
  40.     
  41.     panel                = new GUIC_PanelC            (GUIC_Horizontal, TRUE); /* TRUE means: no space between the objects */
  42.     
  43.     loadButton        = new GUIC_ImageButtonC ("gfx/load.iff");
  44.     saveButton        = new GUIC_ImageButtonC ("gfx/save.iff");
  45.     button6            = new GUIC_ImageButtonC ("gfx/compare.iff");
  46.     button1            = new GUIC_ImageButtonC ("gfx/HTML.iff");
  47.     button2            = new GUIC_ImageButtonC ("gfx/Manager.iff");
  48.     button3            = new GUIC_ImageButtonC ("gfx/Prefs.iff");
  49.     button4            = new GUIC_ImageButtonC ("gfx/Help.iff");
  50.     button5            = new GUIC_ImageButtonC ("gfx/Shell.iff");
  51.     
  52.     panel->add (loadButton);
  53.     panel->add (saveButton);
  54.     panel->add (button6);
  55.     panel->add (button1);
  56.     panel->add (button2);
  57.     panel->add (button3);
  58.     panel->add (button4);
  59.     panel->add (button5);
  60.  
  61.     add(panel);
  62.     
  63.     activate();
  64.     setTitle("Gallery");
  65.     setGuideContext("Usage");
  66.  
  67.     app->addPrefs("Usage", this);
  68. }
  69. MainWindowC::~MainWindowC         (VOID)
  70. {
  71.     cleanUp();
  72. }
  73.  
  74. /*********************************************************************************************************/
  75.  
  76. STRPTR    MainWindowC::getClass    (VOID)
  77. {
  78.     return "MainWindowC";
  79. }
  80.  
  81. BOOL     MainWindowC::action         (GUIC_EventC &event)
  82. {
  83.     switch (event.id)
  84.         {
  85.         case GUIC_GadgetEvent:
  86.             return TRUE;
  87.             break;
  88.         case GUIC_ObjectEvent:
  89.             if (event.object == (GUIC_GUIObjectC *) loadButton)
  90.                 {
  91.                 app->setBusy(TRUE);
  92.                 if (fileRequester.request(this, GUIC_Load))
  93.                     {
  94.                     if (! load(fileRequester.getFileName()))
  95.                         {
  96.                         GUIC_ErrorC err ("Error", "Could not load data file.");
  97.                         err.request(this);
  98.                         }
  99.                     }
  100.                 app->setBusy(FALSE);
  101.                 }
  102.             else if (event.object == (GUIC_GUIObjectC *) saveButton)
  103.                 {
  104.                 app->setBusy(TRUE);
  105.                 if (fileRequester.request(this, GUIC_Save))
  106.                     {
  107.                     if (! save(fileRequester.getFileName()))
  108.                         {
  109.                         GUIC_ErrorC err ("Error", "Could not save data file.");
  110.                         err.request(this);
  111.                         }
  112.                     }
  113.                 app->setBusy(FALSE);
  114.                 }
  115.             else if (event.object == (GUIC_GUIObjectC *) button1) // HTML
  116.                 {
  117.                 screen->remove(pWindow);
  118.                 screen->remove(mWindow);
  119.                 screen->remove(cWindow);
  120.                 screen->add(hWindow);
  121.                 }
  122.             else if (event.object == (GUIC_GUIObjectC *) button2) // Manager
  123.                 {
  124.                 screen->remove(pWindow);
  125.                 screen->remove(hWindow);
  126.                 screen->remove(cWindow);
  127. //                screen->add(mWindow);
  128.                 GUIC_MessageC message ("Gallery", "Sorry, but this part of Gallery\nis not yet implemented.", "Ok");
  129.                 message.request(this);
  130.                 }
  131.             else if (event.object == (GUIC_GUIObjectC *) button3) // Prefs
  132.                 {
  133.                 screen->remove(hWindow);
  134.                 screen->remove(mWindow);
  135.                 screen->remove(cWindow);
  136.                 screen->add(pWindow);
  137.                 }
  138.             else if (event.object == (GUIC_GUIObjectC *) button4) // Guide
  139.                 {
  140.                 app->showAmigaGuide(screen, "MAIN");
  141.                 }
  142.             else if (event.object == (GUIC_GUIObjectC *) button5) // Shell
  143.                 {
  144.                 GUIC_SystemC::runProgram(pWindow->st_shellCommand->get(), 50000);
  145.                 }
  146.             else if (event.object == (GUIC_GUIObjectC *) button6) // Compare
  147.                 {
  148.                 screen->remove(hWindow);
  149.                 screen->remove(mWindow);
  150.                 screen->remove(pWindow);
  151.                 screen->add(cWindow);
  152.                 }
  153.             return TRUE;
  154.             break;
  155.         case GUIC_OpenWindow:
  156.             return TRUE;
  157.             break;
  158.         case GUIC_CloseWindow:
  159.             return FALSE;
  160.             break;
  161.         }
  162.     return FALSE;
  163. }
  164.  
  165. BOOL        MainWindowC::load            (STRPTR file)
  166. {
  167.     STRPTR s = 0;
  168.     
  169.     try
  170.         {
  171.         GUIC_FileC f(file);
  172.         
  173.         s = f.readLine();
  174.         if (!s) return FALSE;
  175.         
  176.         if (! Stricmp(s, ("Gallery #1")) )
  177.             {
  178.             s = f.readLine();
  179.             if (!s) return FALSE;
  180.             pWindow->ps_thumbnailPath->set(s);
  181.             
  182.             s = f.readLine();
  183.             if (!s) return FALSE;
  184.             pWindow->ps_temporaryPath->set(s);
  185.  
  186.             s = f.readLine();
  187.             if (!s) return FALSE;
  188.             pWindow->si_thumbnailWidth->set(atol(s));
  189.  
  190.             s = f.readLine();
  191.             if (!s) return FALSE;
  192.             pWindow->si_thumbnailHeight->set(atol(s));
  193.  
  194.             s = f.readLine();
  195.             if (!s) return FALSE;
  196.             pWindow->cb_thumbnailHide->set( Stricmp(s, "TRUE") ? FALSE : TRUE);
  197.  
  198.             s = f.readLine();
  199.             if (!s) return FALSE;
  200.             pWindow->fs_pattern1->set(s);
  201.  
  202.             s = f.readLine();
  203.             if (!s) return FALSE;
  204.             pWindow->fs_pattern2->set(s);
  205.  
  206.             s = f.readLine();
  207.             if (!s) return FALSE;
  208.             pWindow->fs_sound1->set(s);
  209.  
  210.             s = f.readLine();
  211.             if (!s) return FALSE;
  212.             pWindow->fs_sound2->set(s);
  213.  
  214.             s = f.readLine();
  215.             if (!s) return FALSE;
  216.             pWindow->st_filename->set(s);
  217.  
  218.             s = f.readLine();
  219.             if (!s) return FALSE;
  220.             pWindow->cy_suffix->setActive(atol(s));
  221.  
  222.             s = f.readLine();
  223.             if (!s) return FALSE;
  224.             pWindow->cb_frames->set( Stricmp(s, "TRUE") ? FALSE : TRUE);
  225.  
  226.             s = f.readLine();
  227.             if (!s) return FALSE;
  228.             pWindow->si_frameWidth->set(atol(s));
  229.  
  230.             s = f.readLine();
  231.             if (!s) return FALSE;
  232.             pWindow->si_tableLines->set(atol(s));
  233.  
  234.             s = f.readLine();
  235.             if (!s) return FALSE;
  236.             pWindow->si_tableColumns->set(atol(s));
  237.  
  238.             s = f.readLine();
  239.             if (!s) return FALSE;
  240.             pWindow->si_tableBorderSize->set(atol(s));
  241.  
  242.             s = f.readLine();
  243.             if (!s) return FALSE;
  244.             pWindow->cb_showSize->set( Stricmp(s, "TRUE") ? FALSE : TRUE);
  245.  
  246.             s = f.readLine();
  247.             if (!s) return FALSE;
  248.             pWindow->cb_showDate->set( Stricmp(s, "TRUE") ? FALSE : TRUE);
  249.  
  250.             s = f.readLine();
  251.             if (!s) return FALSE;
  252.             pWindow->cb_showDimensions->set( Stricmp(s, "TRUE") ? FALSE : TRUE);
  253.  
  254.             s = f.readLine();
  255.             if (!s) return FALSE;
  256.             pWindow->st_tableColor1->set(s);
  257.  
  258.             s = f.readLine();
  259.             if (!s) return FALSE;
  260.             pWindow->st_tableColor2->set(s);
  261.             
  262.             s = f.readLine();
  263.             if (!s) return FALSE;
  264.             hWindow->ps_path->set(s);
  265.             }
  266.         else if (! Stricmp(s, ("Gallery #2")) )
  267.             {
  268.             s = f.readLine();
  269.             if (!s) return FALSE;
  270.             pWindow->ps_thumbnailPath->set(s);
  271.             
  272.             s = f.readLine();
  273.             if (!s) return FALSE;
  274.             pWindow->ps_temporaryPath->set(s);
  275.  
  276.             s = f.readLine();
  277.             if (!s) return FALSE;
  278.             pWindow->si_thumbnailWidth->set(atol(s));
  279.  
  280.             s = f.readLine();
  281.             if (!s) return FALSE;
  282.             pWindow->si_thumbnailHeight->set(atol(s));
  283.  
  284.             s = f.readLine();
  285.             if (!s) return FALSE;
  286.             pWindow->cb_thumbnailHide->set( Stricmp(s, "TRUE") ? FALSE : TRUE);
  287.  
  288.             s = f.readLine();
  289.             if (!s) return FALSE;
  290.             pWindow->fs_pattern1->set(s);
  291.  
  292.             s = f.readLine();
  293.             if (!s) return FALSE;
  294.             pWindow->fs_pattern2->set(s);
  295.  
  296.             s = f.readLine();
  297.             if (!s) return FALSE;
  298.             pWindow->fs_sound1->set(s);
  299.  
  300.             s = f.readLine();
  301.             if (!s) return FALSE;
  302.             pWindow->fs_sound2->set(s);
  303.  
  304.             s = f.readLine();
  305.             if (!s) return FALSE;
  306.             pWindow->st_filename->set(s);
  307.  
  308.             s = f.readLine();
  309.             if (!s) return FALSE;
  310.             pWindow->cy_suffix->setActive(atol(s));
  311.  
  312.             s = f.readLine();
  313.             if (!s) return FALSE;
  314.             pWindow->cb_frames->set( Stricmp(s, "TRUE") ? FALSE : TRUE);
  315.  
  316.             s = f.readLine();
  317.             if (!s) return FALSE;
  318.             pWindow->si_frameWidth->set(atol(s));
  319.  
  320.             s = f.readLine();
  321.             if (!s) return FALSE;
  322.             pWindow->si_tableLines->set(atol(s));
  323.  
  324.             s = f.readLine();
  325.             if (!s) return FALSE;
  326.             pWindow->si_tableColumns->set(atol(s));
  327.  
  328.             s = f.readLine();
  329.             if (!s) return FALSE;
  330.             pWindow->si_tableBorderSize->set(atol(s));
  331.  
  332.             s = f.readLine();
  333.             if (!s) return FALSE;
  334.             pWindow->cb_showSize->set( Stricmp(s, "TRUE") ? FALSE : TRUE);
  335.  
  336.             s = f.readLine();
  337.             if (!s) return FALSE;
  338.             pWindow->cb_showDate->set( Stricmp(s, "TRUE") ? FALSE : TRUE);
  339.  
  340.             s = f.readLine();
  341.             if (!s) return FALSE;
  342.             pWindow->cb_showDimensions->set( Stricmp(s, "TRUE") ? FALSE : TRUE);
  343.  
  344.             s = f.readLine();
  345.             if (!s) return FALSE;
  346.             pWindow->st_tableColor1->set(s);
  347.  
  348.             s = f.readLine();
  349.             if (!s) return FALSE;
  350.             pWindow->st_tableColor2->set(s);
  351.             
  352.             s = f.readLine();
  353.             if (!s) return FALSE;
  354.             pWindow->fs_up->set(s);
  355.             
  356.             s = f.readLine();
  357.             if (!s) return FALSE;
  358.             pWindow->fs_left->set(s);
  359.             
  360.             s = f.readLine();
  361.             if (!s) return FALSE;
  362.             pWindow->fs_right->set(s);
  363.  
  364.             s = f.readLine();
  365.             if (!s) return FALSE;
  366.             hWindow->ps_path->set(s);
  367.             }
  368.         else return FALSE;
  369.         }
  370.     catch (GUIC_Exception &ex) { return FALSE; }
  371.  
  372.     return TRUE;
  373. }
  374. BOOL        MainWindowC::save        (STRPTR file)
  375. {
  376.     try
  377.         {
  378.         GUIC_FileC f(file, GUIC_Write);
  379.         
  380.         f.writeLn("Gallery #2");
  381.         f.writeLn(pWindow->ps_thumbnailPath->get());
  382.         f.writeLn(pWindow->ps_temporaryPath->get());
  383.         f.writeLn(pWindow->si_thumbnailWidth->get());
  384.         f.writeLn(pWindow->si_thumbnailHeight->get());
  385.         f.writeLn(pWindow->cb_thumbnailHide->get());
  386.         f.writeLn(pWindow->fs_pattern1->get());
  387.         f.writeLn(pWindow->fs_pattern2->get());
  388.         f.writeLn(pWindow->fs_sound1->get());
  389.         f.writeLn(pWindow->fs_sound2->get());
  390.         f.writeLn(pWindow->st_filename->get());
  391.         f.writeLn(pWindow->cy_suffix->getActive());
  392.         f.writeLn(pWindow->cb_frames->get());
  393.         f.writeLn(pWindow->si_frameWidth->get());
  394.         f.writeLn(pWindow->si_tableLines->get());
  395.         f.writeLn(pWindow->si_tableColumns->get());
  396.         f.writeLn(pWindow->si_tableBorderSize->get());
  397.         f.writeLn(pWindow->cb_showSize->get());
  398.         f.writeLn(pWindow->cb_showDate->get());
  399.         f.writeLn(pWindow->cb_showDimensions->get());
  400.         f.writeLn(pWindow->st_tableColor1->get());
  401.         f.writeLn(pWindow->st_tableColor2->get());
  402.         f.writeLn(pWindow->fs_up->get());
  403.         f.writeLn(pWindow->fs_left->get());
  404.         f.writeLn(pWindow->fs_right->get());
  405.         
  406.         f.writeLn(hWindow->ps_path->get());
  407.         }
  408.     catch (GUIC_Exception &ex) { return FALSE; }
  409.  
  410.     return TRUE;
  411. }
  412.  
  413. /*********************************************************************************************************/
  414.  
  415. VOID         MainWindowC::cleanUp    (VOID)
  416. {
  417.     delete loadButton;
  418.     delete saveButton;
  419.     delete button1;
  420.     delete button2;
  421.     delete button3;
  422.     delete button4;
  423.     delete button5;
  424.     delete button6;
  425.     
  426.     delete panel;
  427. }
  428.  
  429.